﻿Public Class SubscribeTags
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub grvTagSubscribe_SelectedIndexChanged(sender As Object, e As EventArgs) Handles grvTagSubscribe.SelectedIndexChanged
        Try

            Dim aCookie As HttpCookie = Request.Cookies("userIdCookie")
            Dim userId = Convert.ToInt32(aCookie.Value)

            'check if tag already exists to current user
            Dim countTag As TagSubscribersManagement = New TagSubscribersManagement()
            Dim myCountTag = countTag.SelectCountTagsByTagIdUserId(Convert.ToInt32(grvTagSubscribe.SelectedValue), userId)

            If (myCountTag = 0) Then
                Dim insertTag As TagSubscribersManagement = New TagSubscribersManagement()

                Dim myDate As DateTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)

                insertTag.InsertTagSubscriber(userId, myDate, Convert.ToInt32(grvTagSubscribe.SelectedValue))

                lblMessage.Text = "You have been subscribed"
            Else
                lblMessage.Text = "You have already subscribed to this tag"
            End If

        Catch ex As Exception

        End Try
    End Sub
End Class